<?php
namespace Home\Controller;

use Think\Controller;

/*vendor("WXPayAPI.lib.JsApiPay");*/

class IndexController extends Controller
{
    /**
     * 首页
     */
    public function index()
    {
        //取首页轮播图
        $imageTable = M('image_info');
        $image = $imageTable->field('id,image_name,image_path')->select();
        // dump($image);
        $imgBaseUrl = C('REMOTE_IMG_BASE_URL');
        for ($i = 0; $i < count($image); $i++) {
            $image[$i]['image_path'] = $imgBaseUrl . $image[$i]['image_path'];
        }
        $this->assign('image', $image);
        $newsTable = M('mes_publish');
        $news = $newsTable->where('status=1')->order('publisherTime desc')->limit('5')->select();
        for ($i = 0; $i < count($news); $i++) {
            $news[$i]['homepage'] = $imgBaseUrl . $news[$i]['homepage'];
        }
        //取首页底部菜单
        $menuTable = M("wx_public_menu","jt_");
        //取一级菜单
        $mainButtons = $menuTable -> where("status='1'") -> group('button') -> field('id,button') -> select();
        //根据一级菜单取二级菜单
        foreach($mainButtons as $key => $value){
            $subButtons = $menuTable -> where("status='1' and button='%s'",$value['button']) -> field("id,sub_button,url") -> order("sub_button") -> select();
            $mainButtons[$key]['sub_buttons'] = $subButtons;
        }
        //dump($mainButtons);

        $this->assign('news', $news);
        $this -> assign("menu",$mainButtons);
        $this->display();
    }
}